<template>
  <div id="my">
    <!-- <Loadmore :top-method="loadTop" ref="loadmore"> -->
    <router-link to="/personalInfo" class="top">
      <div class="img">
        <img :src="userObj.pic?userObj.pic:userImg" width="62" height="62" />
      </div>
      <div class="myInf">
        <div>
          <h3 style="display:inline">昵称:</h3>
          <h3 style="display:inline;margin-left:0px">{{userObj.username?userObj.username:userObj.id}}</h3>
        </div>
        <p>
          <span>ID:{{userObj.id}}</span>
        </p>
        <span class="btn">
          <img src="../image/icon_white_next.png" width="60" alt="">
        </span>
      </div>
    </router-link>
    <!-- 导航子组件 -->
    <div class="mynav" v-if="type != 'clinic'">
      <my-nav></my-nav>
    </div>
    <!-- 列表子组件 -->
    <div class="menu-list">
      <!-- //我是医生 -->
      <menu-list v-if="type != 'clinic'"></menu-list>
      <!-- 我是诊室 -->
      <menu-list1 v-if="type == 'clinic'"></menu-list1>
      <!-- 我是普通用户 -->
      <!-- <menu-list2 v-if="type != 'clinic'&&type != 'doctor'"></menu-list2> -->
    </div>
    <!-- </Loadmore> -->
    <!-- <div>技术服务由西安天通物联科技有限公司提供</div> -->
  </div>
</template>
<script>
  import {
    Loadmore
  } from 'mint-ui';
  import myNav from '../components/my/mynav.vue'
  import menuList from '../components/my/menuList.vue'
  import menuList1 from '../components/my/menuList1.vue'
  import menuList2 from '../components/my/menuList2.vue'
  export default {
    data() {
      return {
        userImg: require("../image/icon_doctor@2x_03.png"), //默认头像
        userid: "",
        type: '',
        userObj: {}, //用户信息
      }
    },
    methods: {
      // 登录拦截
      isLogin() {
        this.userid = localStorage.getItem("loginMobile");
        if (!this.userid) {
          this.$router.push({
            name: 'login1'
          })
        }
      },
      //创建直播课程 判断如果认证过了就可以创建 否则去认证页面
      goCreateCourse() {
        //判断用户是否认证 如果认证审核通过
        this.$api.get(this.$api.baseURLSchool, "select_cid/user/" + this.userid, {}, r => {
          if (r.data.info.per_app_status == "1") {
            this.$router.push({
              name: 'createCourse'
            });
          } else {
            this.$router.push({
              name: 'authentication'
            });
          }
        }, err => {
          console.log(err);
        })
      },
      //根据用户id获取用户信息
      getUserData() {
        if (this.userid) {
          this.$api.get(this.$api.baseURLSchool, "select_cid/user/" + this.userid, {}, r => {
            if (r.data.ret == 1) {
              this.userObj = r.data.info;
            }
          }, err => {
            console.log(err);
          })
        }
      },
      //下拉刷新
      loadTop() {
        setTimeout(() => {
          this.getUserData();
        }, 20);
        this.$refs.loadmore.onTopLoaded();
      },
    },
    computed: {

    },
    components: {
      Loadmore,
      'my-nav': myNav,
      'menu-list': menuList,
      'menu-list1': menuList1,
      'menu-list2': menuList2,
    },
    beforeRouteEnter(to, from, next) {
      next(
        vm => {
          vm.getUserData()

        }
      );
    },
    created() {
      this.type = localStorage.getItem('type')
      this.type = JSON.parse(this.type)
      this.isLogin();
      this.getUserData();
    },
  }

</script>
<style lang="scss" scoped>


</style>
